﻿#include "searchhotel.h"
#include "ui_searchhotel.h"
#include<QDateTime>
#include<QDebug>

SearchHotel::SearchHotel(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SearchHotel)
{
    ui->setupUi(this);

    initWindowsUnits();
}

SearchHotel::~SearchHotel()
{
    delete ui;
}

void SearchHotel::initWindowsUnits()
{
    m_searchHotelHeader = new SearchHotelHeader();
    ui->lwg_content->addItem("");
    ui->lwg_content->setItemWidget(ui->lwg_content->item(0),m_searchHotelHeader);
    ui->lwg_content->item(0)->setSizeHint(QSize(0, 210));  //每次改变Item的高度

    connect(m_searchHotelHeader,SIGNAL(signalGainHotelInfoList(QString)),
            this, SLOT(slotGainHotelInfoListForClean(QString)));
}

void SearchHotel::slotSetHotelInfoList(bool result, QString msg)
{
    if(result)
    {
        if (m_searchHotelContentVector.size()== 0)
        {
            m_searchHotelHeader->setCount(GlobalVars::count);
        }

        SearchHotelContent *searchHotelContent = new SearchHotelContent();
        m_searchHotelContentVector.append(searchHotelContent);
        int size = m_searchHotelContentVector.size();
        ui->lwg_content->addItem("");
        ui->lwg_content->setItemWidget(ui->lwg_content->item(size),searchHotelContent);
        ui->lwg_content->item(size)->setSizeHint(QSize(0, 145));  //每次改变Item的高度
        searchHotelContent->setCount(size);

        connect(searchHotelContent,SIGNAL(signalGainHotelDetails(const QString&)),
                this, SIGNAL(signalGainHotelDetailsSearch(const QString&)));
        connect(searchHotelContent,SIGNAL(signalWatchComment()),
                this, SIGNAL(signalWatchCommentSearch()));
    }else
    {
        if (msg == "没有记录")                   /// 没有符合条件的酒店的提示图片
        {

        }else                                             /// 没有下一条记录
        {

        }

//        m_imageCount = 0;
    }
}

///重新搜索时进行清除 -- HotelInfoList
void SearchHotel::slotGainHotelInfoListForClean(QString msg)
{
    m_inTime = m_searchHotelHeader->getInTime();
    m_outTime = m_searchHotelHeader->getOutTime();

    emit signalGainHotelInfoListSocket(msg);

    while (ui->lwg_content->count() > 1)
    {
        QListWidgetItem * item = ui->lwg_content->takeItem(1);
        delete item;
    }
    m_searchHotelContentVector.clear();
}

void SearchHotel::slotHotelSearchImage(const QString& hotelID, const QImage& image)
{
    qDebug() << "searchHotelContentVector.size = " << m_searchHotelContentVector.size();
    for (int i = 0 ; i < m_searchHotelContentVector.size(); i++)
    {
        if (hotelID ==  m_searchHotelContentVector[i]->getHotelID())
        {
            m_searchHotelContentVector[i]->setImage(image);
            break;
        }
    }

}
